<script lang="ts" setup>
import { ref, watch, onMounted } from "vue";

const props = defineProps(["question", "isEdit"]);

const checkItem = ref("");

const emit = defineEmits(["onChange"]);
const onChange = (res: any) => {
  console.log("判断", res, checkItem);
  emit("onChange", [res]);
};

onMounted(() => {
  console.log("当前判断题：");
  if (props.question.answer) {
    checkItem.value = props.question.answer.join("");
  } else {
    checkItem.value = "";
  }
});
watch(
  () => props.question,
  (newValue, oldValue) => {
    // console.log("监测到判断题变了：", newValue, oldValue);
    if (newValue.answer) {
      checkItem.value = newValue.answer.join("");
    } else {
      checkItem.value = "";
    }
  }
);
</script>

<template>
  <el-radio-group
    v-model="checkItem"
    class="examination-select-group"
    :disabled="isEdit"
    @change="onChange"
  >
    <el-radio label="R">正确</el-radio>
    <el-radio label="W">错误</el-radio>
  </el-radio-group>
</template>
